﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using UniversityManagementSystem.DAL;

namespace UniversityManagementSystem.UI
{
    public partial class TeacherEntry : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!IsPostBack)
                {
                    Department department = new Department();
                    Teacher teacher = new Teacher();
                    List<Department> allDepartments = new List<Department>();
                    List<string> allDesignations = new List<string>();
                    allDepartments = department.GetAllDepartments();
                    allDesignations = teacher.GetAllDesignations();
                    departmentDropDownList.DataSource = allDepartments;
                    departmentDropDownList.DataValueField = "DepartmentCode";
                    departmentDropDownList.DataTextField = "DepartmentName";
                    departmentDropDownList.DataBind();
                    designationDropDownList.DataSource = allDesignations;
                    designationDropDownList.DataBind();
                }
            }
            catch (Exception)
            {
                messageLabel.Text = "Error While Loading Page.";
                messageLabel.ForeColor = System.Drawing.Color.Red;
            }
            
        }

        protected void saveButton_Click(object sender, EventArgs e)
        {
            try
            {
                Teacher aTeacher = new Teacher();
                string saveTeacherMessage = "";
                aTeacher.TeacherName = nameTextBox.Text;
                aTeacher.TeacherAddress = addressTextBox.Text;
                aTeacher.TeacherEmail = emailTextBox.Text;
                aTeacher.TeacherContact = contactNoTextBox.Text;
                aTeacher.TeacherDesignation = designationDropDownList.SelectedItem.ToString();
                aTeacher.TeacherDeparment = departmentDropDownList.SelectedValue;
                saveTeacherMessage = aTeacher.SaveAteacher(assignedCreditTextBox.Text);
                messageLabel.Text = saveTeacherMessage;
                messageLabel.ForeColor = System.Drawing.Color.Blue;
            }
            catch (Exception)
            {
                messageLabel.Text = "Unable to add the teacher,Please try again.";
                messageLabel.ForeColor = System.Drawing.Color.Red;
            }
        }

    }
}